// 这里没用React.lazy，是因为它没法配合vite的热加载动态更新组件，所以替换成 '@loadable/component'，它可以
// import {lazy} from 'react';
import loadable from '@loadable/component';
import pMinDelay from 'p-min-delay';

import Loading from '@/components/Loading';
import {
    LOGIN, NOTFOUND, HOME, ACCOUNT, MESSAGE, ABOUT, AGREEMENT, USER_AGREEMENT, CONTENT_AGREEMENT, CATEGORY, DISCOVERY, MERCH, MERCH_DETAIL, MERCH_EDIT, EDIT_HISTORY,
    WORK_DETAIL, ROLE_DETAIL, WORK_EDIT, ROLE_EDIT, SEARCH, WEEK_TOP, REGISTER,
} from '@/config/url';


const Home = loadable(() => pMinDelay(import('@/pages/Home'), 0), { fallback: <Loading/> });
const Login = loadable(() => import('@/pages/Login'), { fallback: <Loading/> });
const NotFound = loadable(() => import('@/pages/NotFound'), { fallback: <Loading/> });
const Account = loadable(() => import('@/pages/Account'), { fallback: <Loading/> });
const Message = loadable(() => import('@/pages/Message'), { fallback: <Loading/> });
const About = loadable(() => import('@/pages/About'), { fallback: <Loading/> });
const Agreement = loadable(() => import('@/pages/Agreement'), { fallback: <Loading/> });
const UserAgreement = loadable(() => import('@/pages/UserAgreement'), { fallback: <Loading/> });
const ContentAgreement = loadable(() => import('@/pages/ContentAgreement'), { fallback: <Loading/> });
const Search = loadable(() => import('@/pages/Search'), { fallback: <Loading/> });
const Register = loadable(() => import('@/pages/Register'), { fallback: <Loading/> });

// 确保url唯一，在渲染路由时url充当的是组件的key
export const baseRouters = [
    {
        url: HOME,
        icon: 'icon-home',
        label: '首页',
        component: Home,
    },
    {
        url: LOGIN,
        icon: '',
        label: '欢迎登录',
        component: Login,
        layout: null,
    },
    {
        url: REGISTER,
        icon: '',
        label: '欢迎注册',
        component: Register,
    },
    {
        url: NOTFOUND,
        icon: '',
        label: '404',
        component: NotFound,
    },
    {
        url: ACCOUNT,
        icon: "icon-account-center",
        label: '个人中心',
        component: Account,
    },
    {
        url: MESSAGE,
        icon: '',
        label: '消息中心',
        component: Message,
    },
    {
        url: ABOUT,
        icon: '',
        label: '关于我们',
        component: About,
    },
    {
        url: AGREEMENT,
        icon: '',
        label: '隐私政策',
        component: Agreement,
    },
    {
        url: USER_AGREEMENT,
        icon: '',
        label: '用户协议',
        component: UserAgreement,
    },
    {
        url: CONTENT_AGREEMENT,
        icon: '',
        label: '发布内容协议',
        component: ContentAgreement,
    },
    {
        url: SEARCH,
        icon: '',
        label: '搜索',
        component: Search,
    },
];

// 需要登录 或 有权限 才能访问的路由
/*
    code转换demo：(以/分割，首字母大写，-转换为驼峰；code可以理解成url)
        permission/manage -> pages/Permission/Manage/index.jsx
        user/manage-list -> pages/User/ManageList/index.jsx

 * routers: {
 *      url: xxxx,              // 选填，页面路由，如果没有url就会把code处理后的结果作为url；如果有url，那么url必须以/开头，不用携带域名
 *      code: 'xxx/xxx/xxx',    // 根据code映射组件路径 permission/manage -> pages/Permission/Manage/index.jsx
 *      children: [],           // 子路由
 *      icon: '',               // 页面菜单的icon名字，iconfont图标库的icon名字
 *      label: '',              // 页面菜单的名称
 *      layout: '',             // 页面的布局名称
 *      showInMenu: boolean,    // 是否展示在菜单上
 *      index: boolean,         // 当根路径未配置时的默认跳转路径
 *      rest,                   // 其他数据
 * }
*/
export const pageRouters = [
    {
        code: MERCH, // 没有配置url，code转换后作为url
        icon: 'icon-upload',
        label: '谷子详情',
        showInMenu: true,
        index: false,
    },
    {
        code: MERCH_EDIT,
        icon: 'icon-upload',
        label: '谷子编辑',
        showInMenu: false,
        index: false,
    },
    {
        code: MERCH_DETAIL,
        icon: 'icon-upload',
        label: '谷子详情',
        showInMenu: false,
        index: false,
    },
    {
        code: EDIT_HISTORY,
        icon: 'icon-upload',
        label: '变更历史',
        showInMenu: false,
        index: false,
    },
    {
        code: DISCOVERY, // 没有配置url，code转换后作为url
        icon: 'icon-discovery',
        label: '发现',
        showInMenu: true,
        index: false,
    },

    {
        code: WORK_DETAIL,
        icon: 'icon-upload',
        label: '作品详情',
        showInMenu: false,
        index: false,
    },
    {
        code: WORK_EDIT,
        icon: 'icon-upload',
        label: '作品编辑',
        showInMenu: false,
        index: false,
    },
    {
        code: ROLE_DETAIL,
        icon: 'icon-upload',
        label: '角色详情',
        showInMenu: false,
        index: false,
    },
    {
        code: ROLE_EDIT,
        icon: 'icon-upload',
        label: '角色编辑',
        showInMenu: false,
        index: false,
    },
    {
        code: WEEK_TOP,
        icon: 'icon-upload',
        label: '周榜',
        showInMenu: false,
        index: false,
    },
    {
        code: CATEGORY,
        icon: 'icon-upload',
        label: '品类',
        showInMenu: false,
        index: false,
    },
];
